
//原理：利用栈的思想，先进后出，然后考虑空格的特殊情况  hello  world! --->world! hello
//leetcode: https://leetcode.cn/problems/fan-zhuan-dan-ci-shun-xu-lcof/description/
class Solution {
public:
    string reverseMessage(string s) {
	vector<string> vc1;
	string stmp = "";
	string s1 = "";
	//压栈或者放入vector是一个道理

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != ' ')
		{
			stmp = stmp + s[i];
		}
		else
		{
			if (stmp != "")
			{
				vc1.push_back(stmp);
			}
			stmp = "";
		}
		if (i == s.size() - 1 && stmp != "")
		{
			vc1.push_back(stmp);
		}

	}

	string res = "";
	for (int i = vc1.size() - 1; i >= 0; i--)
	{
		res = res + vc1[i];
		if (i > 0)
		{
			res = res + " ";
		}
	}

	//cout << res <<"结束"<<endl;
	return res;
    }
};